import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

public class ClientExample {
    public static void main(String[] args) {
        try (Socket socket = new Socket("localhost", 8888);
             Scanner in = new Scanner(System.in);
             PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
             Scanner serverIn = new Scanner(socket.getInputStream())) {
            System.out.print("请输入要发送的消息: ");
            String message = in.nextLine();
            out.println(message);
            String response = serverIn.nextLine();
            System.out.println("收到服务器响应: " + response);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}